// 路由管理模块
class DevToolsRouter {
    constructor(app) {
        this.app = app;
        this.currentTool = 'json-formatter';
        this.initRouting();
    }

    initRouting() {
        // URL 路由处理
        const urlParams = new URLSearchParams(window.location.search);
        const tool = urlParams.get('tool');
        
        if (tool) {
            this.currentTool = tool;
        }

        // 处理浏览器前进后退
        window.addEventListener('popstate', (e) => {
            if (e.state && e.state.tool) {
                this.switchTool(e.state.tool, false);
            }
        });
    }

    switchTool(toolId, updateHistory = true) {
        if (this.currentTool === toolId) return;

        this.currentTool = toolId;

        // 更新URL
        if (updateHistory) {
            const newUrl = `${window.location.pathname}?tool=${toolId}`;
            window.history.pushState({ tool: toolId }, '', newUrl);
        }

        // 通知应用切换工具
        this.app.loadTool(toolId);
    }

    getCurrentTool() {
        return this.currentTool;
    }
}